﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db;
using HengTong.Model.Db.Hr;


namespace HengTong.ViewModel.Person.SysPersonTrainExamVms
{
    public partial class SysPersonTrainExamListVm : BasePagedListVM<SysPersonTrainExamView, SysPersonTrainExamSearcher>
    {
        protected override IEnumerable<IGridColumn<SysPersonTrainExamView>> InitGridHeader()
        {
            return new List<GridColumn<SysPersonTrainExamView>>
            {
                this.MakeGridHeader(x => x.PersonName),
                this.MakeGridHeader(x => x.PersonTrainBatcheName),
                this.MakeGridHeader(x => x.Score),
                this.MakeGridHeader(x => x.ScoreReportId).SetFormat(ScoreReportIdFormat),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        private List<ColumnFormatInfo> ScoreReportIdFormat(SysPersonTrainExamView entity, object val)
        {
            return new List<ColumnFormatInfo>
            {
                ColumnFormatInfo.MakeDownloadButton(ButtonTypesEnum.Button, entity.ScoreReportId),
                ColumnFormatInfo.MakeViewButton(ButtonTypesEnum.Button, entity.ScoreReportId, 640, 480),
            };
        }


        public override IOrderedQueryable<SysPersonTrainExamView> GetSearchQuery()
        {
            var query = DC.Set<SysPersonTrainExam>()
                .CheckEqual(Searcher.PersonId, x => x.PersonId)
                .CheckEqual(Searcher.PersonTrainBatcheId, x => x.PersonTrainBatcheId)
                .CheckEqual(Searcher.Score, x => x.Score)
                .Select(x => new SysPersonTrainExamView
                {
                    ID = x.ID,
                    PersonName = x.Person.Name,
                    PersonTrainBatcheName = x.PersonTrainBatche.TrainName,
                    Score = x.Score,
                    ScoreReportId = x.ScoreReportId,
                })
                .OrderBy(x => x.ID);
            return query;
        }
    }

    public class SysPersonTrainExamView : SysPersonTrainExam
    {
        [Display(Name = "姓名")] public String PersonName { get; set; }
        [Display(Name = "培训名称")] public String PersonTrainBatcheName { get; set; }
    }
}